import { Rule, RuleType } from '@midwayjs/decorator'

export class LoginDTO {
  @Rule(RuleType.string().required())
  username: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string

  @Rule(RuleType.string())
  verify: string

  @Rule(RuleType.bool())
  remember_me: boolean
}

@Rule(LoginDTO)
export class RegisterDTO extends LoginDTO {
  @Rule(RuleType.any()
    .required()
    .valid(RuleType.ref('password'))
  )
  confirm_password: string
}

export class UserDTO {
  @Rule(RuleType.string().required())
  username: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string

  @Rule(RuleType
    .string()
    .pattern(/^[0-9]+$/)
  )
  phone: string

  @Rule(RuleType.string().email())
  email: string

  @Rule(RuleType.string())
  realname: string

  @Rule(RuleType.string())
  nickname: string

  @Rule(RuleType.string())
  avatar: string

  @Rule(RuleType.string())
  user_type: string

  @Rule(RuleType.bool())
  active: boolean

  @Rule(RuleType.string())
  remark: string

  @Rule(RuleType.number())
  role_id: number
}

@Rule(UserDTO)
export class UserUpdateDTO extends UserDTO {
  @Rule(RuleType.string().required())
  id: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
  )
  password: string
}

export class UserChangePasswordDTO {
  @Rule(RuleType.string().required())
  id: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  old_password: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string
}

export class WechatLoginDTO {
  @Rule(RuleType.string().required())
  code: string

  @Rule(RuleType.string().required())
  encryptedData: string

  @Rule(RuleType.string().required())
  iv: string
}
